<HTML>
<HEAD>
<TITLE>Walkover distribution</TITLE>
</HEAD>
<BODY>
<STYLE>

BODY {
	font-family: sans-serif;
	font-size: 11;
}

</STYLE>
<?php

require_once("database.inc.php");

$dbh = connect_db("dbm");

$series = array();
$wos = array();
$blocksize = 8;

$leagueid = 14;
if (is_numeric($_GET['id'])) $leagueid = $_GET['id'];

$query = mysql_query("SELECT * FROM series WHERE CountryID = $leagueid", $dbh);

while ($row = mysql_fetch_array($query)) {
	$series[$row['level']][$row['SeriesID']] = $row['SeriesName'];
}

$query = mysql_query("SELECT seriesid, count(*) num FROM `teams_2006-03-13` WHERE userid != 0 AND leagueid = $leagueid GROUP BY seriesid", $dbh);

while ($row = mysql_fetch_array($query)) {
	$wos[$row['seriesid']] = $row['num'];
}

echo "<TABLE>\n\t<TR><TD>Level</TD><TD>Distribution</TD></TR>\n";
foreach (array_keys($series) as $level) {
	echo "\t<TR><TD>$level</TD><TD><CENTER>";
	$i = 0;
	foreach (array_keys($series[$level]) as $serie) {
		$i++;
		$color = 0;
		if ($wos[$serie] > 0) {
			$color = $wos[$serie];
		} else {
			$wos[$serie] = 0;
		}
		echo "<IMG SRC=\"0-8/{$color}.png\" HEIGHT=\"$blocksize\" WIDTH=\"$blocksize\" TITLE=\"{$series[$level][$serie]} ({$wos[$serie]})\" ALT=\"{$series[$level][$serie]}\"/>";
		$curlevel = $level;
		if ($curlevel > 6) $curlevel = 6;
		if ($level >= 3 &! ($i%pow(2, $curlevel))) echo "<BR/>\n";
	}
	echo "</CENTER></TD></TR>\n";
}
echo "</TABLE>\n";

echo "Color code:<BR/>\n<BR/>\n";
echo "<IMG SRC=\"0-8/0.png\" HEIGHT=\"$blocksize\" WIDTH=\"$blocksize\"/> No active users<BR/>\n";
echo "<IMG SRC=\"0-8/1.png\" HEIGHT=\"$blocksize\" WIDTH=\"$blocksize\"/> 1 active user<BR/>\n";

for ($i = 2; $i <= 8 ;$i++) {
	echo "<IMG SRC=\"0-8/{$i}.png\" HEIGHT=\"$blocksize\" WIDTH=\"$blocksize\"/> $i active users<BR/>\n";
}

?>

</BODY>
</HTML>
